﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

using Redboil.Bfp.Core;
using Redboil.Bfp.Model;
using Redboil.Bfp.Service;

namespace Redboil.Bfp.Web.Services {
    /// <summary>
    /// REST风格的服务，提供CRUD的操作示例；
    /// 通过调用DAO（通过容器注入）提供的方法返回结果；
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceContract]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class SampleService {
        private ISampleService sampleService;

        public SampleService() {
            sampleService = Container.Instance.Resolve<ISampleService>();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //[WebInvoke(UriTemplate = "", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
        [WebGet(UriTemplate = "", ResponseFormat=WebMessageFormat.Json)]
        public IList<User> GetUsers() {
            IList<User> userList = new List<User>() {
                new User { Oid = 11111, Account = "111" },
                new User { Oid = 22222, Account = "222" },
                new User { Oid = 33333, Account = "333" },
            };
            return userList;
        }

        [WebGet(UriTemplate = "{Id}", ResponseFormat = WebMessageFormat.Json)]
        public User GetUserById(String id) {
            User user = new User() { Oid = 11111, Account = "111" };
            return user;
        }

        [WebInvoke(UriTemplate = "", Method = "POST", RequestFormat = WebMessageFormat.Json)]
        public void CreateUser(User instance) {
            //sampleService.CreateUser(instance);
        }

        [WebInvoke(UriTemplate = "{Id}", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
        public void UpdateUserById(String id, User instance) {
            //userDao.CreateUser(instance);
        }

        [WebInvoke(UriTemplate = "", Method = "PUT", RequestFormat = WebMessageFormat.Json)]
        public void UpdateUsers(User instance) {
            //userDao.CreateUser(instance);
        }


        [WebInvoke(UriTemplate = "{Id}", Method = "DELETE")]
        public void DeleteUserById(String id) {
            //
        }

        [WebInvoke(UriTemplate = "", Method = "DELETE", RequestFormat = WebMessageFormat.Json)]
        public void DeleteUsers(IList<User> userList) {
            //
        }


        /// <summary>检测用户名是否存在</summary>
        /// <param name="userName">用户名</param>
        /// <returns>返回bool false 用户名可用 true 用户名已经被注册 </returns>
        //bool ExistenceUserName(string userName);

    }
}